/**
 * Util.js contains single functions that do not belong
 * into any specific class/object
 */

var util = {
	// template function searches through a tmpl string and replaces 
	// all matches with values from the data or an empty string. 
	template: function (tmpl,data){
	    return tmpl.replace(/#{(\w*)}/g,function(){return data[arguments[1]] || "";});
	},
	width: function() {
		// some devices report their width / height wrong
		// this is fixed in latest client/proxy configurations,
		// but we'll still force the layout to portrait, if the width is not explicitly set to 320px
		return window.innerWidth == 320 ? 320 : 240;
	},
	networkErrorMessage: function(statusCode, retryMwl) {
		switch(statusCode) {
			case 401: 
				return qype.strings.networkErrorAuth;
			default:
				return sprintf(qype.strings.networkError, retryMwl);
		}
	},
    log: function(msg) {
		var node = document.getElementById("console");
		if(node) {
			node.innerHTML += "<p>"+msg+"</p>";
		} else if (console && console.log) {
			console.log(msg);
		}
	}
}